/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts.Carrera;

import javax.servlet.http.*;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Andreina Wilhelm
 */
public class AgregarCarreraForm extends org.apache.struts.action.ActionForm {
    
    private String codigo;
    private String nombre;
    private String tipo;

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo.trim();
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre.trim();
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    

    /**
     *
     */
    public AgregarCarreraForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    
    
    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        // Nueva instancia de ActionErrors
        ActionErrors errors = new ActionErrors();

        // validar campo de codigo este lleno
        if (this.codigo == null || this.codigo.equals("")) {
            errors.add("err_cod", new ActionMessage("errors.required"));
        }

        // validar campo de nombre este lleno
        if (this.nombre == null || this.nombre.equals("")) {
            errors.add("err_nom", new ActionMessage("errors.required"));
        }
        
        // validar campo de nombre este lleno
        if (this.tipo == null || this.tipo.equals("")) {
            errors.add("err_tipo", new ActionMessage("errors.required"));
        }
        return errors;
    }
    

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset properties
        this.codigo = "";
        this.nombre = "";
        this.tipo = "";
    }
}
